package cn.bqjr.eily.core.autoconfigure;

import cn.bqjr.eily.core.entity.SysProperties;
import cn.bqjr.eily.utils.SpringContextUtils;
import cn.bqjr.eily.utils.SpringEnvirUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.Executor;

/**
 * 系统bean注册
 */
@Configuration
@EnableConfigurationProperties({SysProperties.class})
@EnableAsync
@Import({SpringContextUtils.class, SpringEnvirUtils.class})
public class SysCoreAutoconfigure {
    private Logger logger = LoggerFactory.getLogger(SysCoreAutoconfigure.class);
    /**
     * 初始化异步任务线程池
     */
    @Bean
    @ConditionalOnMissingClass
    public Executor taskExecutor() {
        logger.debug("Async Executor init successful");
        return new SimpleAsyncTaskExecutor();
    }
}
